import java.util.Arrays;
//数组的拷贝
public class TestDemo {
    public static int []copy(int []array){
        int []copyArray=new int [array.length];
        for (int i = 0; i < array.length; i++) {
            copyArray[i]=array[i];
        }
        return  copyArray;
    }

    public static void main(String[] args) {
        int []array1={1,2,3,4,5,6,7,8,9,10};
        int []array2= Arrays.copyOf(array1,array1.length);
        System.out.println(Arrays.toString(array1));

    }
    public static void main3(String[] args) {
        int []array1={1,2,3,4,5,6,7,8,9,10};
        int []copy_Array=copy(array1);
        System.out.println(Arrays.toString(copy_Array));

    }

    //交换位置
    public static void swap(int []array,int i,int j){
        int tmp=array[i];
        array[i]=array[j];
        array[j]=tmp;
    }

    //数组逆序
    public static void reverse(int []array){
        int i=0;
        int j=array.length-1;
        while(i<j){
            swap(array,i,j);
            i++;
            j--;
        }

    }

    public static void main2(String[] args) {
        int[] array={10,20,30,40};
        System.out.println("逆序前"+Arrays.toString(array));
        reverse(array);
        System.out.println("逆序后"+Arrays.toString(array));
    }

    //冒泡排序
    public static void Bubblesort(int []array){
        for (int i = 0; i < array.length-1; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                if(array[j]>array[j+1]){
                    int tmp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=tmp;
                }
            }

        }
    }

    public static void main1(String[] args) {
        int []array={10,20,130,40};
        System.out.println("排序前"+ Arrays.toString(array));
        Bubblesort(array);
        System.out.println("排序后"+Arrays.toString(array));
    }
}